/*
 * @Author: hongbin
 * @Date: 2021-12-18 13:58:29
 * @LastEditors: hongbin
 * @LastEditTime: 2021-12-18 15:54:50
 * @Description:分页组件
 */
import { View, Text } from "@tarojs/components";
import { styled } from "linaria/lib/react";
import React, { FC, ReactElement } from "react";
import { generatePaginationIndex } from "../../utils";

type T = Parameters<typeof generatePaginationIndex>[number];

interface IProps extends T {
  onChange: (page: number) => void;
}

const Pagination: FC<IProps> = ({
  currentPage,
  onChange,
  ...params
}): ReactElement => {
  return (
    <Container>
      {generatePaginationIndex({ ...params, currentPage }).map(page => (
        <View
          key={page}
          className={currentPage === page ? "primaryButton" : ""}
          onClick={() => {
            onChange(page);
          }}
        >
          <Text>{page}</Text>
        </View>
      ))}
    </Container>
  );
};

export default Pagination;

const Container = styled(View)`
  width: 100vw;
  height: 4rem;
  display: flex;
  align-items: center;
  justify-content: space-evenly;

  & > view {
    width: 3rem;
    height: 3rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #3b969b;
    color: #ccc;
  }
`;
